package cn.bavelee.pokeinstaller;

import android.os.AsyncTask;

/**
 * Created by Bave on 2018/2/2.
 */

public class InstallApkTask extends AsyncTask<Void, Void, Boolean> {
    private final ShellUtils.Result result;
    private ApkInfo mApkInfo;
    private IInstallCallback callback;


    public InstallApkTask(ApkInfo mApkInfo, IInstallCallback callback, ShellUtils.Result result) {
        this.mApkInfo = mApkInfo;
        this.callback = callback;
        this.result = result;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        callback.onPreInstall(mApkInfo);
    }

    @Override
    protected void onPostExecute(Boolean aBoolean) {
        super.onPostExecute(aBoolean);
        callback.onInstalled(mApkInfo, aBoolean);
    }

    @Override
    protected Boolean doInBackground(Void... voids) {
        return PokeInstaller.install(mApkInfo.getApkFile().getPath(), result);
    }
}
